package com.homestay.filter;

import javax.servlet.*;
import java.io.IOException;

public class EncoderFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // 设置请求和响应的字符编码为UTF-8
        servletRequest.setCharacterEncoding("UTF-8");
//        servletResponse.setContentType("text/html;charset=UTF-8");

        // 继续执行过滤器链中的下一个过滤器或目标资源
        filterChain.doFilter(servletRequest, servletResponse);

    }

    @Override
    public void destroy() {

    }
}
